//
//  IGSearchHisManager.m
//  jingdongfang
//
//  Created by BOE on 2018/5/7.
//  Copyright © 2018年 BOE-SBG-CTO. All rights reserved.
//

#import "IGSearchHisManager.h"

static NSString *const kHisKey = @"HisArr";
@implementation IGSearchHisManager

+ (IGSearchHisManager *)shareManager {
    static IGSearchHisManager *manager = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[IGSearchHisManager alloc] init];
    });
    return manager;
}

- (NSArray *)getHisArray {
    NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];
    NSArray *hisArr = [userDefaultes arrayForKey:kHisKey];
    
    return hisArr;
}

- (void)setHisArray:(NSArray *)hisArray {
    NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];
    [userDefaultes setObject:hisArray forKey:kHisKey];
    [userDefaultes synchronize];
}

- (void)addSearchKey:(NSString *)searchKey {
    NSMutableArray *hisMuArr = [NSMutableArray arrayWithArray:[self getHisArray]];
    if ([hisMuArr containsObject:searchKey]) {
        return;
    } else {
        [hisMuArr insertObject:searchKey atIndex:0];
        self.hisArray = hisMuArr;
    }
}

@end
